import {
	RotationChart,
	GetHomeIcon,
	GetRecommendSongSheet,
	GetAllList,
	GetRecommendSongSheetInfo
} from "@/api/index.js"

//准备actions对象——响应组件中用户的动作
const actions = {
	// 获取轮播图
	async getRotationChart(state) {
		let info = await RotationChart()
		state.commit('setRotationChart', info['banners'])
	},

	// 获取首页图标
	async getHomeIcon(state) {
		let info = await GetHomeIcon()
		state.commit('setHomeIcon', info['data'])
	},

	// 获取推荐歌单
	async getRecommendSongSheet(state, limit) {
		let info = await GetRecommendSongSheet(limit)
		state.commit('setRecommendSongSheet', info['result'])
	},

	// 获取所有榜单
	async GetAllList(state) {
		let info = await GetAllList()
		state.commit('setAllList', info['list'])
		return info['list']
	},

	// 获取歌单详情
	async GetRecommendSongSheetInfo(state, nid) {
		let info = await GetRecommendSongSheetInfo(nid)
		state.commit('setRecommendSongSheetInfo',info['playlist']['tracks'])
		return info['playlist']['tracks']
	}
}
//准备mutations对象——修改state中的数据
const mutations = {
	// 修改轮播图
	setRotationChart(state, obj) {
		state.RotationChart = obj
	},

	// 修改首页图标
	setHomeIcon(state, obj) {
		state.HomeIcon = obj
	},

	// 修改推荐歌单
	setRecommendSongSheet(state, obj) {
		state.RecommendSongSheet = obj
	},

	// 修改所有榜单
	setAllList(state, obj) {
		state.AllList = obj
	},

	// 修改榜单内容
	setRecommendSongSheetInfo(state, obj) {
		state.RecommendSongSheetInfo.push(obj)
	}
}
//准备state对象——保存具体的数据
const state = {
	RotationChart: [], // 轮播图列表
	HomeIcon: [], //首页图标列表
	RecommendSongSheet: [], // 推荐歌单
	AllList: [], // 所有榜单
	RecommendSongSheetInfo: [], // 榜单的内容
}


export default ({
	state,
	mutations,
	actions,
	namespaced: true,
})
